package com.jy.adscm.operation.pebase.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.pebase.bean.PeDiseaseType;
import com.jy.adscm.operation.pebase.bean.QueryPeDiseaseType;
import com.jy.adscm.operation.pebase.mapper.mysql.PeDiseaseTypeMapper;
import com.jy.adscm.operation.pebase.service.PeDiseaseTypeService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2019-04-10
 */
@Service
public class PeDiseaseTypeServiceImpl extends ServiceImpl<PeDiseaseTypeMapper, PeDiseaseType> implements PeDiseaseTypeService {
   @Autowired
    JyUserMapper jyUserMapper;

    @Override
    public Page<PeDiseaseType> selectPeDiseaseType(Page<PeDiseaseType> page, QueryPeDiseaseType queryPeDiseaseType) {
        Wrapper<PeDiseaseType>  wrapper  =new EntityWrapper<>();
        if (AdscmBaseUtils.getInstance().isNotEmpty(queryPeDiseaseType.getDiseaseName(),null)){
            wrapper.like("disease_name",queryPeDiseaseType.getDiseaseName());
        }
        if (AdscmBaseUtils.getInstance().isNotEmpty(queryPeDiseaseType.getDiseaseStatus(),null)){
            wrapper.eq("disease_status",queryPeDiseaseType.getDiseaseStatus());
        }
        if (AdscmBaseUtils.getInstance().isNotEmpty(queryPeDiseaseType.getDept(),null)){
            wrapper.eq("dept",queryPeDiseaseType.getDept());
        }
        if (AdscmBaseUtils.getInstance().isNotEmpty(queryPeDiseaseType.getLevel(),null)){
            wrapper.eq("level",queryPeDiseaseType.getLevel());
        }
        if (AdscmBaseUtils.getInstance().isNotEmpty(queryPeDiseaseType.getTa(),null)){
            wrapper.eq("TA",queryPeDiseaseType.getTa());
        }
        if (AdscmBaseUtils.getInstance().isNotEmpty(queryPeDiseaseType.getCreator(),null)){
            wrapper.eq("creator",queryPeDiseaseType.getCreator());
        }
        page = super.selectPage(page, wrapper);
        List<PeDiseaseType> peDiseaseTypes = page.getRecords();
        for (PeDiseaseType peDiseaseType : peDiseaseTypes) {
            if (AdscmBaseUtils.getInstance().isNotEmpty(peDiseaseType.getCreator(),null)){
                JyUser jyUser = jyUserMapper.selectById(peDiseaseType.getCreator());
                if (AdscmBaseUtils.getInstance().isNotEmpty(jyUser,null)){
                    peDiseaseType.setCreatorName(jyUser.getName());
                }else {
                    peDiseaseType.setCreatorName(peDiseaseType.getCreator());
                }
            }
        }
        page.setTotal(super.selectCount(wrapper));

        return page;
    }

    @Override
    public List<JyUser> selectUsers() {
        List<JyUser> jyUsers = jyUserMapper.selectTaskPerformPerson("174");
        return jyUsers;
    }
}
